package com.hpf.cloud.pojo;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.ArrayList;

/**
 * @description:
 * @datetime: 2020/11/29 22:08
 * @author: huangpengfei
 */
@Data
@NoArgsConstructor
@ApiModel(value = "标准响应分页类")
public class PageResult<T> extends CommonResult<T> {

    /**
     * 总条数
     */
    @ApiModelProperty(value = "错误栈信息")
    private long total;

    /**
     * 总页数
     */
    @ApiModelProperty(value = "错误栈信息")
    private long pages;
    
    public PageResult(boolean state, String msg, T data, int code, long total, long pages) {
        super(state, msg, data, code, null);
        this.total = total;
        this.pages = pages;
    }

    public static CommonResult ok(String msg, Object data, long total, long pages) {
        if(data == null) {
            data = new ArrayList<>();
        }

        if(msg == null) {
            msg = "";
        }

        return new PageResult(true, msg, data, ResultCode.SUCCESS.getCode(), total, pages);
    }

    public static CommonResult ok(Object data, long total, long pages) {
        return PageResult.ok(null, data, total, pages);
    }


    public static CommonResult ok() {
        return PageResult.ok(null, 0, 0);
    }
}
